<?php
class Rols_model extends CI_Model {

    var $id_rol = '';
    var $description = '';
    var $status = '';
    private $_tabla = 'rols';

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    public function find($id_rol)
    {
        $query = $this->db->where('id_rol', $id_rol)->get($this->_tabla);
        $rs = $query->result();
        if (isset($rs[0])) {
            return $rs[0];
        } 
        return false;
    }
    
    public function getAll()
    {
        $query = $this->db;
        $query = $query->where('status', 1);
        $query = $this->db->get($this->_tabla);
        return $query->result();
    }
    
    /*public function search($code = null, $description = null, $category = null)
    {
        $query = $this->db;
        if (isset($code) && $code != '') {
            $query = $query->like($this->_tabla.'.code', $code, 'both');
        }
        if (isset($description) && $description != '') {
            $query = $query->like($this->_tabla.'.description', $description);
        }
        if (isset($category) && $category != '') {
            $query = $query->join('product_groups', "product_groups.id = ".$this->_tabla.".group_id", 'left');
            $query = $query->like('product_groups.description', $category);
        }
        $query = $query->where($this->_tabla.'.status', 1);
        $query = $query->get($this->_tabla);
        $rs = $query->result();
        return $rs;
    }*/
    
    public function add($data)
    {
        $this->db->insert($this->_tabla, $data);
        return true;
    }
    
    public function delete($id_rol)
    {
        $this->db->where('id_rol', $id_rol);
        $this->db->update($this->_tabla, array('status' => 0));
        return true; 
    }

    public function update($id_rol, $data)
    {
        
		
        $this->db->where('id_rol', $id_rol);
        $this->db->update($this->_tabla, $data);
        return true;
    }
}